const { src, parallel, dest } = require("gulp");
const ts = require("gulp-typescript");
const less = require('gulp-less');
const cleanCSS = require('gulp-clean-css');

const TS_SRC = 'lib/**/*.ts';

// https://blog.csdn.net/qq_26626113/article/details/79320198

/**
 * 编译 typescript 源文件
 */
function tsjs () {
  const tsProject = ts.createProject('tsconfig.json');
  return src("lib/**/*.ts")
    .pipe(tsProject())
    .js.pipe(dest('./'));
}

/**
 * 构建 typescript 生成 .d.ts
 */
function tsdts () {
  return src(TS_SRC)
    .pipe(ts({
      declaration: true
    })).dts.pipe(dest('./'))
}

/**
 * 编译 less
 */
function lessc () {
  return src('./lib/index.less')
    .pipe(less())
    .pipe(cleanCSS({ level: 2 }))
    .pipe(dest('./'))
}

exports.default = parallel(tsjs, lessc, tsdts);
